package com.mark.servlet;

import java.io.IOException;

import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.add.Job1;
import com.get.Job1Impl;
import com.mark.database.Mark1;
import com.mark.toolImpl.GetMarkImpl;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class GetMarkServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		HttpSession session = request.getSession();
		JSONArray messageArray=new JSONArray();
		if(session.getAttribute("uId")!=null){
		int Uid=Integer.valueOf(String.valueOf(session.getAttribute("uId")));
		GetMarkImpl get = new GetMarkImpl();
			ArrayList MarkList=get.getMark1List(Uid);
			System.out.println(get.getMark1List(Uid).size()+"...."+Uid);
			if(MarkList.size()>0){
				for(int i=0;i<MarkList.size();i++){
					Mark1 m1=(Mark1) MarkList.get(i);
					JSONObject message=new JSONObject();
					Job1Impl ji=new Job1Impl();
					Job1 j1=ji.getJob1(m1.getJobId());
					message.put("jobName", j1.getJobName());
					message.put("place", j1.getPlace());
					message.put("salary", j1.getSalary());
					message.put("paytype", j1.getPayType());
					message.put("jobid", j1.getId());
					message.put("date", j1.getWorkTime());
					messageArray.add(message);
				}
			}
			else{
				JSONObject message=new JSONObject();
				message.put("job", null);
				messageArray.add(message);
			}
		}
		else{
			JSONObject message=new JSONObject();
			message.put("job", "无此工作");
			messageArray.add(message);
		}
		response.getWriter().print(messageArray);  
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
